package com.lanou.impl;

import com.github.pagehelper.PageHelper;
import com.lanou.mapper.TemporayCharges;
import com.lanou.pojo.PaymentMethod;
import com.lanou.pojo.PaymentTempEntity;
import com.lanou.service.TemporayService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class TemporayServiceImpl implements TemporayService {
    @Resource
    private TemporayCharges temporayCharges;
    @Resource
    private com.lanou.mapper.securityDeposit securityDeposit;
    @Override
    public List<PaymentTempEntity> selectTemporayChargesList(String pageNum, String pageSize, String resourceName, String feeUser, String state, String feeItemName, String payType) {

        //处理分页查询
        if(pageNum == null || "".equals(pageNum)){
            pageNum="1";
        }
        if(pageSize == null || "".equals(pageSize)){
            pageSize="5";
        }
        PageHelper.startPage(Integer.valueOf(pageNum),Integer.valueOf(pageSize));



        List<PaymentTempEntity> paymentTempEntities = temporayCharges.selectTemporayChargesList(resourceName, feeUser, state, feeItemName, payType);
        List<PaymentMethod> paymentMethods = securityDeposit.selectPayMethod();
        for (PaymentTempEntity code : paymentTempEntities) {
            for(PaymentMethod name:paymentMethods)
                if (code.getPayType().equals(name.getCode())) {
                    code.setPayType(name.getName());
                }
        }


        return paymentTempEntities;
    }

    @Override
    public void addPaymentTemp(String resourceName, String feeUser, String feeItemName, String payType, String amt, Date operateTime) {
        UUID uuid = UUID.randomUUID();
        String  id=controllerServiceImpl.generateRandomNumber(19);
        String resourceId=controllerServiceImpl.generateRandomNumber(19);
        String feeItemId=controllerServiceImpl.generateRandomNumber(19);
        if (feeUser==null||"".equals(feeUser)){
            feeUser="张三";
        }
        temporayCharges.addPaymentTemp(id,resourceId,feeItemId,resourceName,feeUser,feeItemName,payType,amt,operateTime);

    }

    @Override
    public void updateByid(Date refundTime, String remark, String refundType, String id) {
        temporayCharges.updateByid(refundTime,remark,refundType,id);
    }
}
